﻿using System;
namespace Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg {
    
    
    [global::Xtee.Core.Attributes.XmlTypeAttribute(Name="sidevahendType", Namespace="http://producers.arireg.xtee.riik.ee/producer/arireg", Target=typeof(SidevahendType))]
    public class SidevahendTypeSerializer : global::Xtee.Core.Types.AbstractXteeSerializable {
        
        protected ISidevahendType clazz;
        
        public SidevahendTypeSerializer(ISidevahendType clazz) {
            this.clazz = clazz;
        }
        
        public override void WriteXml(global::Xtee.Core.IXteeXmlWriter Writer) {
            base.WriteXml(Writer);
            Writer.WriteStartElement("sidevahendi_liik");
            if (clazz.SidevahendiLiik!=null) {
                Writer.WriteTypeAttribute("http://producers.arireg.xtee.riik.ee/producer/arireg", "x_sideliik");
                Writer.WriteString(clazz.SidevahendiLiik.ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : SidevahendiLiik");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("sidevahendi_number");
            if (clazz.SidevahendiNumber!=null) {
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.SidevahendiNumber))).ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : SidevahendiNumber");
            }
            Writer.WriteEndElement();
        }
        
        public override void ReadXml(global::Xtee.Core.IXteeXmlReader Reader) {
            base.ReadXml(Reader);
            if (Reader.LocalName=="sidevahendi_liik") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>sidevahendType>sidevahendi_liik");
                }
                clazz.SidevahendiLiik = new global::Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg.XSideliik(Reader.ReadElementString("sidevahendi_liik"));
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>sidevahendType>sidevahendi_liik", Reader.LocalName);
            }
            if (Reader.LocalName=="sidevahendi_number") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>sidevahendType>sidevahendi_number");
                }
                clazz.SidevahendiNumber = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("sidevahendi_number")).Value;
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>sidevahendType>sidevahendi_number", Reader.LocalName);
            }
        }
    }
}
